package com.kuaifawu.lwnlawyerclient.Adapter;

import android.app.Activity;
import android.content.Context;

import android.content.Intent;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.Toast;

import com.kuaifawu.lwnlawyerclient.Lib.ToastView_custom;
import com.kuaifawu.lwnlawyerclient.Model.LWNModel_lawyerInfo;
import com.kuaifawu.lwnlawyerclient.R;

import java.util.List;

/**
 * Created by zhangminglei on 15/2/14.
 */
public class LWNAdapter_growXunzhang extends ArrayAdapter {

    private LayoutInflater mInflater;
    private Context context_this;
    private Activity activity;

    int head_count;
    int foot_count;

    public LWNAdapter_growXunzhang(Context context, int resource, List objects,Activity activity) {
        super(context, resource, objects);
        context_this = context;
        this.mInflater = LayoutInflater.from(context);
        this.activity=activity;
    }

    @Override
    public int getCount() {
        return 1;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_grow_xunzhang, parent, false);
        }

        final String[] string_content = {"再戳一下就告诉你","别戳了真的不知道","一大波勋章正在路上呢","多多答题可能有勋章哦"};

        ImageButton button_daren = (ImageButton)convertView.findViewById(R.id.gc_daren);
        ImageButton button_mingxing = (ImageButton) convertView.findViewById(R.id.gc_mingxing);
        ImageButton button_one = (ImageButton) convertView.findViewById(R.id.gc_xunzhang_one);
        ImageButton button_two = (ImageButton) convertView.findViewById(R.id.gc_xunzhang_two);
        ImageButton button_three = (ImageButton) convertView.findViewById(R.id.gc_xunzhang_three);
        ImageButton button_four = (ImageButton) convertView.findViewById(R.id.gc_xunzhang_four);
        ImageButton button_five = (ImageButton) convertView.findViewById(R.id.gc_xunzhang_five);
        ImageButton button_six = (ImageButton) convertView.findViewById(R.id.gc_xunzhang_six);

        final int xunzhang = Integer.parseInt(LWNModel_lawyerInfo.getInstance().getLabel());
        switch (xunzhang){
            case 0:{
                button_daren.setImageDrawable(context_this.getResources().getDrawable(R.drawable.lc_jz_no_big));
                button_mingxing.setImageDrawable(context_this.getResources().getDrawable(R.drawable.lc_jz_no_big));
            }break;
            case 1:{
                button_daren.setImageDrawable(context_this.getResources().getDrawable(R.drawable.lc_jz_daren));
                button_mingxing.setImageDrawable(context_this.getResources().getDrawable(R.drawable.lc_jz_no_big));
            }break;
            case 2:{
                button_daren.setImageDrawable(context_this.getResources().getDrawable(R.drawable.lc_jz_no_big));
                button_mingxing.setImageDrawable(context_this.getResources().getDrawable(R.drawable.lc_jz_mingxing));
            }break;
            default:{

            }break;
        }

        button_daren.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (xunzhang == 1) {
//                    Toast toast = Toast.makeText(context_this.getApplicationContext(),
//                            "月答题数过百，好棒！", Toast.LENGTH_SHORT);
//                    //toast.setGravity(Gravity.BOTTOM, 0, 0);
//                    toast.show();

                    ToastView_custom toast = new ToastView_custom(context_this.getApplicationContext());
                    toast.showCustom(activity,"月答题数过百，好棒！");
                } else {
//                    Toast toast = Toast.makeText(context_this.getApplicationContext(),
//                            string_content[creatRandomNumber()], Toast.LENGTH_SHORT);
//                   // toast.setGravity(Gravity.BOTTOM, 0, 0);
//                    toast.show();

                    ToastView_custom toast = new ToastView_custom(context_this.getApplicationContext());
                    toast.showCustom(activity,string_content[creatRandomNumber()]);
                }
            }
        });

        button_mingxing.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (xunzhang == 2) {
//                    Toast toast = Toast.makeText(context_this.getApplicationContext(),
//                            "答题过百评价最高，你就是明星！", Toast.LENGTH_SHORT);
//                    //toast.setGravity(Gravity.BOTTOM, 0, 0);
//                    toast.show();


                    ToastView_custom toast = new ToastView_custom(context_this.getApplicationContext());
                    toast.showCustom(activity,"答题过百评价最高，你就是明星！");
                } else {
//                    Toast toast = Toast.makeText(context_this.getApplicationContext(),
//                            string_content[creatRandomNumber()], Toast.LENGTH_SHORT);
//                   // toast.setGravity(Gravity.BOTTOM, 0, 0);
//                    toast.show();

                    ToastView_custom toast = new ToastView_custom(context_this.getApplicationContext());
                    toast.showCustom(activity,string_content[creatRandomNumber()]);
                }
            }
        });

        button_one.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                Toast toast = Toast.makeText(context_this.getApplicationContext(),
//                        string_content[creatRandomNumber()], Toast.LENGTH_SHORT);
//              //  toast.setGravity(Gravity.BOTTOM, 0, 0);
//                toast.show();

                ToastView_custom toast = new ToastView_custom(context_this.getApplicationContext());
                toast.showCustom(activity,string_content[creatRandomNumber()]);
            }
        });

        button_two.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                Toast toast = Toast.makeText(context_this.getApplicationContext(),
//                        string_content[creatRandomNumber()], Toast.LENGTH_SHORT);
//               // toast.setGravity(Gravity.BOTTOM, 0, 0);
//                toast.show();

                ToastView_custom toast = new ToastView_custom(context_this.getApplicationContext());
                toast.showCustom(activity,string_content[creatRandomNumber()]);
            }
        });

        button_three.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                Toast toast = Toast.makeText(context_this.getApplicationContext(),
//                        string_content[creatRandomNumber()], Toast.LENGTH_SHORT);
//               // toast.setGravity(Gravity.BOTTOM, 0, 0);
//                toast.show();

                ToastView_custom toast = new ToastView_custom(context_this.getApplicationContext());
                toast.showCustom(activity,string_content[creatRandomNumber()]);
            }
        });

        button_four.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                Toast toast = Toast.makeText(context_this.getApplicationContext(),
//                        string_content[creatRandomNumber()], Toast.LENGTH_SHORT);
//              //  toast.setGravity(Gravity.BOTTOM, 0, 0);
//                toast.show();

                ToastView_custom toast = new ToastView_custom(context_this.getApplicationContext());
                toast.showCustom(activity,string_content[creatRandomNumber()]);
            }
        });

        button_five.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                Toast toast = Toast.makeText(context_this.getApplicationContext(),
//                        string_content[creatRandomNumber()], Toast.LENGTH_SHORT);
//              //  toast.setGravity(Gravity.BOTTOM, 0, 0);
//                toast.show();

                ToastView_custom toast = new ToastView_custom(context_this.getApplicationContext());
                toast.showCustom(activity,string_content[creatRandomNumber()]);
            }
        });

        button_six.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                Toast toast = Toast.makeText(context_this.getApplicationContext(),
//                        string_content[creatRandomNumber()], Toast.LENGTH_SHORT);
//               // toast.setGravity(Gravity.BOTTOM, 0, 0);
//                toast.show();

                ToastView_custom toast = new ToastView_custom(context_this.getApplicationContext());
                toast.showCustom(activity,string_content[creatRandomNumber()]);
            }
        });

        return convertView;
    }

    private int creatRandomNumber(){
        return (int) (Math.random() * 4);
    }
}
